﻿Imports DTO
Public Class MuaHangDAO
    Public Shared Function LoadMuaHang(ByVal MaPhieu As String) As DataTable
        Dim dtMuaHang As DataTable
        dtMuaHang = New DataTable()
        Dim sql As String
        sql = String.Format("Select * From MuaHang Where MaPhieu={0}", MaPhieu)
        dtMuaHang = CKetNoi.GetData(sql)
        Return dtMuaHang
    End Function

    Public Shared Function Insert(muaHangDTO As MuaHangDTO) As Boolean
        Dim sql As String
        Dim ngay As String = String.Format("{0}-{1}-{2}", muaHangDTO.Ngay.Month, muaHangDTO.Ngay.Date, muaHangDTO.Ngay.Year)
        Dim ngayThanhToan As String = String.Format("{0}-{1}-{2}", muaHangDTO.HanThanhToan.Month, muaHangDTO.HanThanhToan.Date, muaHangDTO.HanThanhToan.Year)
        sql = String.Format("Insert Into MuaHang(Ngay,MaNhanVien,MaNhaCungCap,MaHinhThuc,HanThanhToan,ChietKhau,Vat,ThanhTien,GhiChu) Values ('{0}','{1}','{2}',{3},'{4}',{5},{6},{7},{8})",
                            ngay, muaHangDTO.MaNhanVien, muaHangDTO.MaNhaCungCap, muaHangDTO.MaHinhThuc, ngayThanhToan, muaHangDTO.ChietKhau, muaHangDTO.Vat, muaHangDTO.ThanhTien, muaHangDTO.GhiChu)
        Dim Count As Integer = CKetNoi.ExecNonQuery(sql)
        If Count > 0 Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Shared Function Update(muaHangDTO As MuaHangDTO) As Boolean
        Dim ngay As String = String.Format("{0}-{1}-{2}", muaHangDTO.Ngay.Month, muaHangDTO.Ngay.Date, muaHangDTO.Ngay.Year)
        Dim ngayThanhToan As String = String.Format("{0}-{1}-{2}", muaHangDTO.HanThanhToan.Month, muaHangDTO.HanThanhToan.Date, muaHangDTO.HanThanhToan.Year)
        Dim sql As String = String.Format("Update MuaHang Set Ngay='{0}',MaNhanVien='{1}',NhaCungCap='{2}',MaHinhThuc={3},HanThanhToan='{4}',ChietKhau= {5},Vat={6},ThanhTien={7},GhiChu={8}",
                                          ngay, muaHangDTO.MaNhanVien, muaHangDTO.MaNhaCungCap, muaHangDTO.MaHinhThuc, ngayThanhToan, muaHangDTO.ChietKhau, muaHangDTO.Vat, muaHangDTO.ThanhTien, muaHangDTO.GhiChu)
        Dim Count As Integer = CKetNoi.ExecNonQuery(sql)
        If Count > 0 Then
            Return True
        Else
            Return False
        End If
    End Function
End Class
